//
//  DSSuNingJiaZuViewController.m
//  7.13苏宁框架
//
//  Created by app05 on 15/7/23.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSSuNingJiaZuViewController.h"
#import "MJExtension.h"
#import "DSZNavigationBarView.h"
#import "DSZMoreView.h"
#import "DSZStyleOneCell.h"
#import "DSZSuNJZModel.h"
#import "DSZSuningFamillyTableViewCell.h"
#import "DSZMainViewController.h"
#import "HomeViewController.h"
#import "DSZShopViewController.h"
@interface DSSuNingJiaZuViewController ()<UITableViewDataSource,UITableViewDelegate,navigationBarDelegata,tableViewIndexPathRowDelegate,famillyDelegate>

@property(nonatomic,weak)UIView *moreView;
@property(nonatomic,assign)BOOL flag;
@property (strong, nonatomic) NSArray *famillyArray;
@end

@implementation DSSuNingJiaZuViewController

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.alpha=0;
}

-(NSArray *)famillyArray
{
    _famillyArray=[NSArray array];
    _famillyArray=[DSZSuNJZModel modelArrayWithFilename:@"SuningFamily.plist"];
    return _famillyArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *view=[[UIView alloc]initWithFrame:self.view.bounds];
    self.view=view;
    self.view.backgroundColor=[UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1];
    [self addNavBar];
    
    [self addContentView];
}
-(void)addNavBar
{
    DSZNavigationBarView *nav=[[DSZNavigationBarView alloc]initWithFrame:CGRectZero];
    nav.frame=CGRectMake(0, 20, 320, 44);
    [self.view addSubview:nav];
    nav.delegate=self;
    nav.titleLabel=@"苏宁家族";
}
-(void)addContentView
{
    UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, 320, 380) ];
    tableView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:tableView];
    tableView.delegate=self;
    tableView.dataSource=self;
    tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    //tableView.scrollEnabled=NO;
    tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    
}
-(void)btnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)moreBtnClick
{
    
    if (!self.flag) {
        DSZMoreView *more=[DSZMoreView moreView];
        more.delegate=self;
        more.frame=CGRectMake(185, 65, 146, 186);
        self.moreView=more;
        [self.view addSubview:self.moreView];
        self.flag=YES;
    }
    else
    {
        [self.moreView removeFromSuperview];
        self.moreView=nil;
        self.flag=NO;
    }
}
-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.famillyArray.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID=@"cell";
    //DSZSuningFamillyTableViewCell *cell=[[DSZSuningFamillyTableViewCell alloc]init];
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
    //cell.delegate=self;
    DSZSuningFamillyTableViewCell *cell1=nil;
    cell.userInteractionEnabled=YES;
    if (cell==nil) {
        cell1=[DSZSuningFamillyTableViewCell header];
        cell1.delegate=self;
        cell=cell1;
    }
    
    DSZSuNJZModel *sn=self.famillyArray[indexPath.row];
    cell1.model=sn;
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 63;
}
-(void)famillyDownload
{
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"确定要下载此应用？" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"ok ", nil];
    [alertView show];
}
-(void)dszMoreViewWithIndexRow:(NSInteger)indexPathRow
{
    if (indexPathRow==0) {
        UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        DSZMainViewController *main=[story instantiateViewControllerWithIdentifier:@"main"];
        //DSZMainViewController *main=[[DSZMainViewController alloc]init];
        [self presentViewController: main animated:NO completion:nil];
    }else if (indexPathRow==1)
    {}
    else if (indexPathRow==2)
    {
        UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        
        DSZShopViewController *shop=[story instantiateViewControllerWithIdentifier:@"shop"];
        [self.navigationController pushViewController:shop animated:NO];
        self.flag=YES;
        [self moreBtnClick];
        self.navigationController.navigationBar.alpha=1;
        DSZMainViewController *main=(DSZMainViewController*)self.tabBarController;
        [main hiddenMainTabbar:YES];
    }else if (indexPathRow==3)
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    }
    
}

@end
